﻿using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace WebAppHelloVS2017.Models
{

    public class Worker
    {
        public int ID { set; get; }

        [Display(Name = "First Name")]
        [DataType(DataType.Text)]
        [Required]
        public string FirstName { set; get; }

        [Display(Name = "Last Name")]
        [DataType(DataType.Text)]
        [Required]
        public string LastName { set; get; }

        [Required]
        public Sex Sex { set; get; }

        public double? Rating { set; get; }
        
    }

    public class WorkerDbContext : DbContext
    {
        public WorkerDbContext():base("WorkerDbContext")
        {
            
        }

        public DbSet<Worker> Workers { set; get; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            
            modelBuilder.Conventions.Remove<System.Data.Entity.ModelConfiguration.Conventions.PluralizingTableNameConvention>();
        }

    }

    public class WorkerInitializer : System.Data.Entity.DropCreateDatabaseAlways<WorkerDbContext>
    {
        protected override void Seed(WorkerDbContext context)
        {
            var students = new List<Worker>
            {
                new Worker{ FirstName="Andy",LastName="George",Sex=Sex.Male},
                new Worker{FirstName="Laura",LastName="Smith",Sex = Sex.Female},
                new Worker{FirstName="Jason",LastName="Black",Sex = Sex.Male},
                new Worker{FirstName="Linda",LastName="Queen",Sex = Sex.Female},
                new Worker{FirstName="James",LastName="Brown", Sex = Sex.Male}
            };

            students.ForEach(s => context.Workers.Add(s));
            context.SaveChanges();
        }

    }
}